<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	 public function __construct()
        {
        parent:: __construct();
        $this->load->model('login_model');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
   
		}

	public function index()
	{
	   $data['mensaje']='';
		$this->load->view('login',$data);
      
	}


	public function log()
	{
		$isValidLogin = $this->login_model->getLogin( $this->input->post('username'),md5($this->input->post('password'))); 
	
		if ($isValidLogin) {
			
			$datos=$this->login_model->get_user($this->input->post('username'));
			$sesion_data = array(
                                        'nick' => $this->input->post('username'),
                                        'nombre' => $datos['nombre_usu']  );
                    
                                            
                        $this->session->set_userdata($sesion_data);
			
			switch ($datos['tipo']) {
				
				case 1:
					redirect('admin');
					break;
				case 2:
					redirect('magistrado');
					break;
				case 3:
					redirect('secretario');
					break;
				default:
					
					break;
			}
			
			
			
		}
		else {
			$data['mensaje']='Usuario o Contraseña invalido, intente de nuevo';
			$this->load->view('login',$data);
      
		}
	}



	  function logout()
    {

        $this->session->sess_destroy();
        redirect('login');
    }
}


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */